package com.woniuxy.commons.entity.auth.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * (RbacManager)实体类
 *
 * @author makejava
 * @since 2022-04-28 08:29:27
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@ApiModel(value = "账号对应DTO")
public class RbacManagerDto extends OrganizationComponent implements Serializable {
    private static final long serialVersionUID = -28242985105967762L;

    @ApiModelProperty(value = "账号")
    private String account;




    private List<OrganizationComponent> menuDtoList;


    @Override
    public void addOrganizationComponent(OrganizationComponent data) {
        if (menuDtoList == null) {
            menuDtoList = new ArrayList<>();
        }
        menuDtoList.add(data);
    }

    @Override
    public void removeOrganizationComponent(OrganizationComponent data) {
        if (menuDtoList == null) {
            super.removeOrganizationComponent(data);
        }

        menuDtoList.remove(data);
    }

    @Override
    public boolean isHas(Object perm) {
        long count = menuDtoList.stream()
                .filter(organizationComponent -> {
                    RbacMenuDto rbacMenuDto = (RbacMenuDto) organizationComponent;
                    return rbacMenuDto.isHas(perm);
                })
                .count();

        return count > 0;
    }


}

